package com.yiqi.zhiyuan.feature.order.view;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.EditText;
import android.widget.TextView;

import com.luck.picture.lib.entity.EventEntity;
import com.luck.picture.lib.rxbus2.RxBus;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.zhiyuan.R;
import com.yiqi.zhiyuan.entity.vo.EndPushVO;
import com.yiqi.zhiyuan.entity.vo.OrderVO;
import com.yiqi.zhiyuan.feature.order.contract.OrderInfoContract;
import com.yiqi.zhiyuan.feature.order.dependencies.info.DaggerOrderInfoComponent;
import com.yiqi.zhiyuan.feature.order.dependencies.info.OrderInfoPresenterModule;
import com.yiqi.zhiyuan.framework.ZYConstants;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.yiqi.zhiyuan.common.utils.AppUtil.formatDouble;

public class ScheduleConfirmedActivity extends BaseActivity implements OrderInfoContract.View {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_order_comfrim_total)
    TextView mTvOrderComfrimTotal;
    @BindView(R.id.tv_order_comfrim_starting)
    TextView mTvOrderComfrimStarting;
    @BindView(R.id.tv_order_comfrim_kile)
    TextView mTvOrderComfrimKile;
    @BindView(R.id.tv_order_comfrim_time)
    TextView mTvOrderComfrimTime;
    @BindView(R.id.edt_order_comfrim_road)
    EditText mEdtOrderComfrimRoad;
    @BindView(R.id.tv_order_comfrim_paking)
    EditText mTvOrderComfrimPaking;
    @BindView(R.id.tv_order_comfrim_other)
    EditText mTvOrderComfrimOther;
    @BindView(R.id.tv_order_comfrim_remark)
    EditText mTvOrderComfrimRemark;


    private EndPushVO endPushVO;
    private OrderVO orderVO;

    @Inject
    OrderInfoContract.Presenter mPresenter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_schedule_confirmed;
    }

    @Override
    protected void initInjector() {
        DaggerOrderInfoComponent.builder().orderInfoPresenterModule(new OrderInfoPresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "行程确认", true, true);
    }

    @Override
    protected void initData() {
        orderVO = (OrderVO) this.getIntent().getSerializableExtra("order_info");
        mPresenter.selectDriverOrderDetails(orderVO.getOrderNo(), orderVO.getUseCarType());
        RxBus.getDefault().register(this);
    }

    @OnClick(R.id.btn_order_off_running)
    public void onViewOffRunningClicked() {
        mPresenter.doComfirmTrip(orderVO.getOrderNo(),
                mTvOrderComfrimOther.getText().toString().trim(),
                mTvOrderComfrimPaking.getText().toString().trim(),
                mTvOrderComfrimRemark.getText().toString().trim(),
                mTvOrderComfrimOther.getText().toString().trim(),
                orderVO.getUseCarType()
        );
        RxBus.getDefault().post(new EventEntity(ZYConstants.ORDER_SHOUCHE, 0));

    }

    @OnClick(R.id.btn_order_continue)
    public void onViewContinueClicked() {
        mPresenter.doComfirmTrip(
                orderVO.getOrderNo(),
                mTvOrderComfrimOther.getText().toString().trim(),
                mTvOrderComfrimPaking.getText().toString().trim(),
                mTvOrderComfrimRemark.getText().toString().trim(),
                mEdtOrderComfrimRoad.getText().toString().trim(),
                orderVO.getUseCarType()
        );
        RxBus.getDefault().post(new EventEntity(ZYConstants.ORDER_JIXU, 0));
    }

    @Override
    public void showEndTaskSuccess(EndPushVO data) {

    }

    @Override
    public void showEndTaskError(String errorMsg) {
        showMsg(errorMsg);
    }

    @Override
    public void showStartTaskSuccess() {

    }

    @Override
    public void showStartTaskError(String errorMsg) {

    }

    @Override
    public void showOrderDetailSuccess(OrderVO model) {
        mTvOrderComfrimTotal.setText(formatDouble(model.getTotalPrice()));
        mTvOrderComfrimStarting.setText(formatDouble(model.getStartingPrice()) + "积分");
        mTvOrderComfrimKile.setText(formatDouble(model.getKilePrice()) + "积分");
        mTvOrderComfrimTime.setText(formatDouble(model.getDrivingPrice()) + "积分");
    }

    @Override
    public void showOrderDetailError(String errorMsg) {
        showMsg(errorMsg);
    }

    @Override
    public void showArriveAtLocationSuccess() {

    }

    @Override
    public void showPassengersGettingOnBusSuccess() {

    }

    @Override
    public void showGoNowSuccess() {

    }

    @Override
    public void showComfirmTripSuccess() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxBus.getDefault().unregister(this);
    }


}
